<?php

namespace App\Http\Api\Services\Toutiao;

use App\Exceptions\InvalidRequestException;
use App\Http\Models\MediaWtt;
use App\Http\Services\BaseService;
use Illuminate\Support\Facades\DB;


class MediaService extends BaseService
{
    public function wttEffect($attributes = [])
    {
        if(empty($attributes)){
            throw new InvalidRequestException('数据为空');
        }

        foreach ($attributes as $item){
            $thread_id = $item['thread_id'];
            $flag = MediaWtt::where('thread_id',$thread_id)->exists();
            if($flag){
                unset($item['thread_id']);
                MediaWtt::where('thread_id',$thread_id)->update($item);
            }else{
                MediaWtt::create($item);
            }
        }
        return true;
    }

}
